package com.example.config;

import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.command.ActiveMQTopic;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jms.annotation.EnableJms;
import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
import org.springframework.jms.config.JmsListenerContainerFactory;

import javax.jms.ConnectionFactory;
import javax.jms.Queue;
import javax.jms.Topic;


@Configuration
@EnableJms
public class Config {

    @Bean
    public Queue testQueue(){
        return new ActiveMQQueue("activemq-springboot-test-queue");
    }

    @Bean
    public Topic testTopic(){
        return new ActiveMQTopic("activemq-spring-test-topic");
    }

    // 为Topic指定单独的JmsListenerContainerFactory
    @Bean
    public JmsListenerContainerFactory jmsListenerContainerFactoryForTopic(ConnectionFactory connectionFactory){
        DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
        factory.setConnectionFactory(connectionFactory);
        factory.setPubSubDomain(true);
        return factory;
    }
}
